package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import school.dao.Tool;

public class MySqlStudentDao implements StudentDao {

	@Override
	public Student login(int stuno, String pass) {
		PreparedStatement st = null;
		ResultSet rs = null;
		String sql = "select * from student where stuno=? and pass=?";

		Connection con = Tool.open();
		Student s = null;
		try {
			st = con.prepareStatement(sql);
			st.setInt(1, stuno);
			st.setString(2, pass);
			System.out.println(sql);
			rs = st.executeQuery();
			while (rs.next()) {
				s = new Student();
				s.setId(stuno);
				s.setSname(rs.getString("sname"));
				s.setSex(rs.getString("sex"));
				s.setQq(rs.getString("qq"));
				s.setAddress(rs.getString("address"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException();
		} finally {
			Tool.close(st, con, rs);
		}
		return s;
	}
}